View Javadoc

1   package net.sourceforge.simplegamenet.chess;
2   
3   import java.io.Serializable;
4   
5   abstract public class ChessPiece implements ChessGridSize, Serializable, Cloneable {
6   
7       protected int participantOwnerIndex;
8       protected int x;
9       protected int y;
10  
11      protected ChessPiece(int participantOwnerIndex, int x, int y) {
12          this.participantOwnerIndex = participantOwnerIndex;
13          this.x = x;
14          this.y = y;
15      }
16  
17      public abstract boolean isMoveAllowed(ChessPiece[] pieceGrid,
18                                            int destinationX, int destinationY);
19  
20      public void doMove(ChessPiece[] pieceGrid, int destinationX, int destinationY) {
21          pieceGrid[x * GRID_HEIGHT + y] = null;
22          x = destinationX;
23          y = destinationY;
24          pieceGrid[destinationX * GRID_HEIGHT + destinationY] = this;
25      }
26  
27      public int getParticipantsOwnerIndex() {
28          return participantOwnerIndex;
29      }
30  
31      public boolean isInPlayField() {
32          return (x >= 0 && y >= 0);
33      }
34  
35      public int getX() {
36          return x;
37      }
38  
39      public int getY() {
40          return y;
41      }
42  
43      public Object clone() {
44          try {
45              // Returns a shallow copy
46              return super.clone();
47          } catch (CloneNotSupportedException exception) {
48              return null;
49          }
50      }
51  
52      public abstract int getPieceType();
53  
54      public abstract int getPieceValue();
55  
56  }